package com.lm.jasypt.example;

import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.salt.RandomSaltGenerator;

public class SaltAndIterationExample {
    public static void main(String[] args) {
        // 创建加密器
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        encryptor.setPassword("my-strong-secret-key");
        encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
        encryptor.setPoolSize(4); // 线程池大小

        // 设置盐值生成器和迭代次数
        encryptor.setSaltGenerator(new RandomSaltGenerator());
//        encryptor.setKeyObtentionIterations(1000); // 增加破解难度

        // 加密
        String sensitiveData = "shdxhl";
        String encryptedData = encryptor.encrypt(sensitiveData);
        System.out.println("Encrypted Data: " + encryptedData);

        // 解密
        String decryptedData = encryptor.decrypt(encryptedData);
        System.out.println("Decrypted Data: " + decryptedData);
    }
}

